home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Interfaces & Libraries / Interfaces / CIncludes / iomanip.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  6.5 KB  |  118 lines  |  [TEXT/MPS ]

  1. /*
  2.     iomanip.h -- Streams manipulator functions.
  3.     
  4.     Copyright Apple Computer,Inc.    1994-1995
  5.     All rights reserved.
  6.  
  7. */
  8.  
  9. #ifndef __IOMANIP__
  10. #define __IOMANIP__       1
  11.  
  12. #include <generic.h>
  13. #include <iostream.h>
  14.  
  15. #define SMANIP(T)name2(smanip_,T)
  16. #define SAPP(T)name2(sapply_,T)
  17. #define IMANIP(T)name2(imanip_,T)
  18. #define OMANIP(T)name2(omanip_,T)
  19. #define IOMANIP(T)name2(iomanip_,T)
  20. #define IAPP(T)name2(iapply_,T)
  21. #define OAPP(T)name2(oapply_,T)
  22. #define IOAPP(T)name2(ioapply_,T)
  23.  
  24. /*
  25.  *------------------------------------------------------------------------
  26.  * NOTE: (For users of the following macro)
  27.  * Whenever the following macro is used, proper structure alignment pragma
  28.  * should used to ensure the uniformity of the structure's alignment.
  29.  *------------------------------------------------------------------------
  30.  */
  31. #define IOMANIPdeclare(T)                                               \
  32. class SMANIP(T) {                                                       \
  33.         ios& (*fct)(ios&,T);                                            \
  34.         T arg;                                                          \
  35. public:                                                                 \
  36.         SMANIP(T)(ios& (*f)(ios&, T), T a) :                            \
  37.                         fct(f), arg(a) { }                              \
  38.         friend istream& operator>>(istream& i, const SMANIP(T)& m) {    \
  39.                         ios* s = &i;                                    \
  40.                         (*m.fct)(*s,m.arg);  return i;  }               \
  41.         friend ostream& operator<<(ostream& o, const SMANIP(T)& m) {    \
  42.                         ios* s = &o;                                    \
  43.                         (*m.fct)(*s,m.arg);  return o;  }               \
  44.         };                                                              \
  45. class SAPP(T) {                                                         \
  46.         ios& (*fct)(ios&, T);                                           \
  47. public:                                                                 \
  48.         SAPP(T)(ios& (*f)(ios&,T)) : fct(f) { }                         \
  49.         SMANIP(T) operator()(T a) {                                     \
  50.                         return SMANIP(T)(fct,a);  }                     \
  51.         };                                                              \
  52. class IMANIP(T) {                                                       \
  53.         istream& (*fct)(istream&,T);                                    \
  54.         T arg;                                                          \
  55. public:                                                                 \
  56.         IMANIP(T)(istream& (*f)(istream&, T), T a ) :                   \
  57.                 fct(f), arg(a) { }                                      \
  58.         friend istream& operator>>(istream& s, const IMANIP(T)& m) {    \
  59.                 return(*m.fct)(s,m.arg);                                \
  60.                 }                                                       \
  61.         };                                                              \
  62. class IAPP(T) {                                                         \
  63.         istream& (*fct)(istream&, T);                                   \
  64. public:                                                                 \
  65.         IAPP(T)(istream& (*f)(istream&,T)) : fct(f) { }                 \
  66.         IMANIP(T) operator()(T a) {                                     \
  67.                         return IMANIP(T)(fct,a);  }                     \
  68.         };                                                              \
  69. class OMANIP(T) {                                                       \
  70.         ostream& (*fct)(ostream&,T);                                    \
  71.         T arg;                                                          \
  72. public:                                                                 \
  73.         OMANIP(T)(ostream& (*f)(ostream&, T), T a ) :                   \
  74.                 fct(f), arg(a) { }                                      \
  75.         friend ostream& operator<<(ostream& s, const OMANIP(T)& m) {    \
  76.                 return(*m.fct)(s,m.arg);                                \
  77.                 }                                                       \
  78.         };                                                              \
  79. class OAPP(T) {                                                         \
  80.         ostream& (*fct)(ostream&, T);                                   \
  81. public:                                                                 \
  82.         OAPP(T)(ostream& (*f)(ostream&,T)) : fct(f) { }                 \
  83.         OMANIP(T) operator()(T a) {                                     \
  84.                         return OMANIP(T)(fct,a);  }                     \
  85.         };                                                              \
  86. class IOMANIP(T) {                                                      \
  87.         iostream& (*fct)(iostream&,T);                                  \
  88.         T arg;                                                          \
  89. public:                                                                 \
  90.         IOMANIP(T)(iostream& (*f)(iostream&, T), T a ) :                \
  91.                 fct(f), arg(a) { }                                      \
  92.         friend istream& operator>>(iostream& s, const IOMANIP(T)& m) {  \
  93.                 return(*m.fct)(s,m.arg);                                \
  94.                 }                                                       \
  95.         friend ostream& operator<<(iostream& s, const IOMANIP(T)& m) {  \
  96.                 return(*m.fct)(s,m.arg);                                \
  97.                 }                                                       \
  98.         };                                                              \
  99. class IOAPP(T) {                                                        \
  100.         iostream& (*fct)(iostream&, T);                                 \
  101. public:                                                                 \
  102.         IOAPP(T)(iostream& (*f)(iostream&,T)) : fct(f) { }              \
  103.         IOMANIP(T) operator()(T a) {                                    \
  104.                         return IOMANIP(T)(fct,a);  }                    \
  105.         };                                                              \
  106.  
  107. IOMANIPdeclare(int);
  108. IOMANIPdeclare(long);
  109.  
  110. SMANIP(int)     setbase(int b);         /* 10, 8, 16 or 0 */
  111. SMANIP(long)    resetiosflags(long b);
  112. SMANIP(long)    setiosflags(long b);
  113. SMANIP(int)     setfill(int f);
  114. SMANIP(int)     setprecision(int p);
  115. SMANIP(int)     setw(int w);
  116.  
  117. #endif    /* __IOMANIP__ */
  118.